<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.4.0">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.15.2/css/all.min.css">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/animate.css@3.1.1/animate.min.css">

<script class="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"littlefxc.github.io","root":"/","images":"/images","scheme":"Mist","version":"8.2.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":false,"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}};
  </script>
<meta property="og:type" content="website">
<meta property="og:title" content="一年春又来">
<meta property="og:url" content="http://littlefxc.github.io/page/3/index.html">
<meta property="og:site_name" content="一年春又来">
<meta property="og:locale" content="zh_CN">
<meta property="article:author" content="一年春又来">
<meta name="twitter:card" content="summary">


<link rel="canonical" href="http://littlefxc.github.io/page/3/">


<script class="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : true,
    isPost : false,
    lang   : 'zh-CN'
  };
</script>
<title>一年春又来</title>
  




  <noscript>
  <style>
  body { margin-top: 2rem; }

  .use-motion .menu-item,
  .use-motion .sidebar,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header {
    visibility: visible;
  }

  .use-motion .header,
  .use-motion .site-brand-container .toggle,
  .use-motion .footer { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle,
  .use-motion .custom-logo-image {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line {
    transform: scaleX(1);
  }

  .search-pop-overlay, .sidebar-nav { display: none; }
  .sidebar-panel { display: block; }
  </style>
</noscript>

<link rel="alternate" href="/atom.xml" title="一年春又来" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <h1 class="site-title">一年春又来</h1>
      <i class="logo-line"></i>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu">
        <li class="menu-item menu-item-home"><a href="/" rel="section"><i class="home                          //首页 fa-fw"></i>首页</a></li>
        <li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="archive          //归档 fa-fw"></i>归档</a></li>
        <li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="th           //分类 fa-fw"></i>分类</a></li>
        <li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="tags                     //标签 fa-fw"></i>标签</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</div>
        
  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>

  <aside class="sidebar">

    <div class="sidebar-inner sidebar-overview-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">一年春又来</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap site-overview-item animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">234</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">38</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">125</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



        </div>
      </div>
    </div>
  </aside>
  <div class="sidebar-dimmer"></div>


    </header>

    
  <div class="back-to-top" role="button">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


    <div class="main-inner index posts-expand">

    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="http://littlefxc.github.io/2022/01/14/docs/JVM/JVM-%E8%99%9A%E6%8B%9F%E6%9C%BA%E6%80%A7%E8%83%BD%E7%9B%91%E6%8E%A7%E6%95%85%E9%9A%9C%E5%A4%84%E7%90%86%E5%B7%A5%E5%85%B7/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="一年春又来">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一年春又来">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/2022/01/14/docs/JVM/JVM-%E8%99%9A%E6%8B%9F%E6%9C%BA%E6%80%A7%E8%83%BD%E7%9B%91%E6%8E%A7%E6%95%85%E9%9A%9C%E5%A4%84%E7%90%86%E5%B7%A5%E5%85%B7/" class="post-title-link" itemprop="url">虚拟机性能监控故障处理工具</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2022-01-14 07:42:05" itemprop="dateCreated datePublished" datetime="2022-01-14T07:42:05+08:00">2022-01-14</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2022-05-10 09:25:02" itemprop="dateModified" datetime="2022-05-10T09:25:02+08:00">2022-05-10</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/Java/" itemprop="url" rel="index"><span itemprop="name">Java</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          
      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="http://littlefxc.github.io/2021/12/31/docs/%E5%BE%AE%E6%9C%8D%E5%8A%A1/Ribbon/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="一年春又来">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一年春又来">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/2021/12/31/docs/%E5%BE%AE%E6%9C%8D%E5%8A%A1/Ribbon/" class="post-title-link" itemprop="url">Ribbon</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2021-12-31 07:57:21" itemprop="dateCreated datePublished" datetime="2021-12-31T07:57:21+08:00">2021-12-31</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2022-05-10 09:28:24" itemprop="dateModified" datetime="2022-05-10T09:28:24+08:00">2022-05-10</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%88%86%E5%B8%83%E5%BC%8F%E7%B3%BB%E7%BB%9F/" itemprop="url" rel="index"><span itemprop="name">分布式系统</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h2 id="负载均衡介绍"><a href="#负载均衡介绍" class="headerlink" title="负载均衡介绍"></a>负载均衡介绍</h2><p>将请求或者说流量，以期望的规则分摊到多个操作单元上进行执行。</p>
<p>通过它可以实现横向扩展(scale out)，将冗余的作用发挥为高可用。另外，还可以物尽其用，提升资源使用率。</p>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/2021/12/31/docs/%E5%BE%AE%E6%9C%8D%E5%8A%A1/Ribbon/#more" rel="contents">
                阅读全文 &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="http://littlefxc.github.io/2021/12/31/docs/%E6%BC%8F%E6%B4%9E%E4%BF%AE%E5%A4%8D/centos7%E4%B8%8Bopenssh%E5%8D%87%E7%BA%A7%E6%96%B9%E6%B3%95%EF%BC%88%E7%BC%96%E8%AF%91%E5%AE%89%E8%A3%85%EF%BC%89/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="一年春又来">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一年春又来">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/2021/12/31/docs/%E6%BC%8F%E6%B4%9E%E4%BF%AE%E5%A4%8D/centos7%E4%B8%8Bopenssh%E5%8D%87%E7%BA%A7%E6%96%B9%E6%B3%95%EF%BC%88%E7%BC%96%E8%AF%91%E5%AE%89%E8%A3%85%EF%BC%89/" class="post-title-link" itemprop="url">centos7下openssh升级方法（编译安装）</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2021-12-31 07:57:21" itemprop="dateCreated datePublished" datetime="2021-12-31T07:57:21+08:00">2021-12-31</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2022-05-10 09:29:32" itemprop="dateModified" datetime="2022-05-10T09:29:32+08:00">2022-05-10</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/FAQ/" itemprop="url" rel="index"><span itemprop="name">FAQ</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <p>注意：<br>首先打开两个或以上的shell连接，因为在升级过程中如果升级失败会导致不发新建shell连接；升级后使用xshell6,7连接，openssh版本对应修改，下载地址：<a target="_blank" rel="noopener" href="https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/">https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/</a></p>
<ol>
<li><p>解压：tar zxvf openssh-8.2p1.tar.gz</p>
</li>
<li><p>查看当前安装的ssh rpm -qa|grep ssh</p>
</li>
<li><p>卸载当前的</p>
<p> ssh rpm -e –nodeps openssh-askpass-5.3p1-94.el6.x86_64 openssh-clients-5.3p1-94.el6.x86_64 openssh-5.3p1-94.el6.x86_64 openssh-server-5.3p1-94.el6.x86_64</p>
</li>
<li><p>安装依赖包 yum install -y openssl-devel</p>
</li>
<li><p>删除/etc/ssh/下的密钥对，编译新的ssh</p>
<p> rm -f /etc/ssh/ssh_host_*<br> cd openssh-8.2p1<br> ./configure –prefix=/usr –sysconfdir=/etc/ssh<br> make &amp;&amp; make install</p>
</li>
<li><p>安装成功之后，查看版本 ssh-V</p>
</li>
<li><p>修改配置文件 sshd_config 把permitrootlogin xxx去掉注释 改成 permitrootlogin yes<br> 把 #UseDNS no 修改 UseDNS no</p>
</li>
<li><p>把sshd拷贝到 /etc/init.d下面</p>
<p> cp -a contrib/redhat/sshd.init /etc/init.d/sshd<br> cp -a contrib/redhat/sshd.pam /etc/pam.d/sshd.pam<br> chmod +x /etc/init.d/sshd<br> chkconfig –add sshd<br> systemctl enable sshd<br> chkconfig sshd on<br> mv  /usr/lib/systemd/system/sshd.service  /opt/ （执行后如提示没有文件，忽略即可）<br> mv  /usr/lib/systemd/system/sshd.socket  /opt/ （执行后如提示没有文件，忽略即可）</p>
</li>
</ol>
<p>9.启动 /etc/init.d/sshd 后面无需加start等参数。</p>

      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="http://littlefxc.github.io/2021/12/29/docs/DDD/DDD/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="一年春又来">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一年春又来">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/2021/12/29/docs/DDD/DDD/" class="post-title-link" itemprop="url">DDD</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2021-12-29 01:07:46" itemprop="dateCreated datePublished" datetime="2021-12-29T01:07:46+08:00">2021-12-29</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2022-05-10 09:25:32" itemprop="dateModified" datetime="2022-05-10T09:25:32+08:00">2022-05-10</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/DDD/" itemprop="url" rel="index"><span itemprop="name">DDD</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h2 id="DDD-的目标"><a href="#DDD-的目标" class="headerlink" title="DDD 的目标"></a>DDD 的目标</h2><p>DDD 的目标是帮助我们创造一个可测试的、可伸缩的、组织良好的高质量软件模型。</p>
<h2 id="架构"><a href="#架构" class="headerlink" title="架构"></a>架构</h2><h2 id="分层架构"><a href="#分层架构" class="headerlink" title="分层架构"></a>分层架构</h2><p><img src="/Users/fengxuechao/Library/Application%20Support/typora-user-images/image-20220401113015069.png" alt="image-20220401113015069"></p>
<ul>
<li>重要原则：每层只能与位于其下方的层发生耦合</li>
</ul>
<p>依赖注入原则 – spring</p>
<p>六边形架构</p>

      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="http://littlefxc.github.io/2021/12/28/docs/%E5%BE%AE%E6%9C%8D%E5%8A%A1/zookeeper%E5%AE%89%E8%A3%85/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="一年春又来">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一年春又来">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/2021/12/28/docs/%E5%BE%AE%E6%9C%8D%E5%8A%A1/zookeeper%E5%AE%89%E8%A3%85/" class="post-title-link" itemprop="url">Zookeeper安装</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2021-12-28 07:39:23" itemprop="dateCreated datePublished" datetime="2021-12-28T07:39:23+08:00">2021-12-28</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2022-05-10 09:28:51" itemprop="dateModified" datetime="2022-05-10T09:28:51+08:00">2022-05-10</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%88%86%E5%B8%83%E5%BC%8F%E7%B3%BB%E7%BB%9F/" itemprop="url" rel="index"><span itemprop="name">分布式系统</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <p>[TOC]</p>
<h2 id="下载"><a href="#下载" class="headerlink" title="下载"></a>下载</h2><blockquote>
<p>下载地址：<a target="_blank" rel="noopener" href="http://zookeeper.apache.org/">http://zookeeper.apache.org/</a></p>
</blockquote>
<p>下载过程就不说了，我们下载了最新的<code>zookeeper-3.4.14</code>。</p>
<h2 id="安装"><a href="#安装" class="headerlink" title="安装"></a>安装</h2><p><strong>1、上传安装包</strong></p>
<p>把下载的最新的包（如：zookeeper-3.4.14.tar.gz）上传到服务器，上传的方式也不多说了。</p>
<p><strong>2、解压</strong></p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ tar zxvf zookeeper-3.4.14.tar.gz</span><br></pre></td></tr></table></figure>

<p><strong>3、移动到/usr/local目录下</strong></p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ ln -s zookeeper-3.4.14 /usr/<span class="built_in">local</span>/zookeeper</span><br></pre></td></tr></table></figure>

<h2 id="服务器分配"><a href="#服务器分配" class="headerlink" title="服务器分配"></a>服务器分配</h2><table>
<thead>
<tr>
<th>主机名</th>
<th>IP</th>
</tr>
</thead>
<tbody><tr>
<td>centos-node1</td>
<td>192.168.99.101</td>
</tr>
<tr>
<td>centos-node2</td>
<td>192.168.99.102</td>
</tr>
<tr>
<td>centos-node3</td>
<td>192.168.99.103</td>
</tr>
</tbody></table>
<h2 id="集群配置"><a href="#集群配置" class="headerlink" title="集群配置"></a>集群配置</h2><p>Zookeeper集群原则上需要2n+1个实例才能保证集群有效性，所以集群规模至少是3台。</p>
<p>下面演示如何创建3台的Zookeeper集群，N台也是如此。</p>
<p><strong>1、创建数据文件存储目录</strong></p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$ <span class="built_in">cd</span> /usr/<span class="built_in">local</span>/zookeeper</span><br><span class="line">$ mkdir data</span><br></pre></td></tr></table></figure>

<p><strong>2、添加主配置文件</strong></p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$ <span class="built_in">cd</span> conf</span><br><span class="line">$ cp zoo_sample.cfg zoo.cfg</span><br></pre></td></tr></table></figure>

<p><strong>3、修改配置</strong></p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ vi zoo.cfg</span><br></pre></td></tr></table></figure>

<p>先把<code>dataDir=/tmp/zookeeper</code>注释掉，然后添加以下核心配置。</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">dataDir=/usr/<span class="built_in">local</span>/zookeeper/data</span><br><span class="line">server.1=centos-node1:2888:3888</span><br><span class="line">server.2=centos-node2:2888:3888</span><br><span class="line">server.3=centos-node3:2888:3888</span><br></pre></td></tr></table></figure>

<p><strong>4、创建myid文件</strong></p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">$ <span class="built_in">cd</span> ../data</span><br><span class="line">$ touch myid</span><br><span class="line">$ <span class="built_in">echo</span> <span class="string">&quot;1&quot;</span>&gt;&gt;myid</span><br></pre></td></tr></table></figure>

<p>每台机器的myid里面的值对应server.后面的数字x。</p>
<p><strong>5、开放3个端口</strong></p>
<p>使用 iptables</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">$ sudo /sbin/iptables -I INPUT -p tcp --dport 2181 -j ACCEPT</span><br><span class="line">$ sudo /sbin/iptables -I INPUT -p tcp --dport 2888 -j ACCEPT</span><br><span class="line">$ sudo /sbin/iptables -I INPUT -p tcp --dport 3888 -j ACCEPT</span><br><span class="line"></span><br><span class="line">$ sudo /etc/rc.d/init.d/iptables save</span><br><span class="line">$ sudo /etc/init.d/iptables restart</span><br><span class="line"></span><br><span class="line">$ sudo /sbin/iptables -L -n</span><br><span class="line">Chain INPUT (policy ACCEPT)</span><br><span class="line">target     prot opt <span class="built_in">source</span>               destination         </span><br><span class="line">ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:3888 </span><br><span class="line">ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:2888 </span><br><span class="line">ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:2181</span><br></pre></td></tr></table></figure>

<p>或者 firewalld</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 查看当前区域</span></span><br><span class="line">$ firewall-cmd --get-active-zones</span><br><span class="line"><span class="comment"># 新建一个自定义服务</span></span><br><span class="line">$ firewall-cmd --new-service=zookeeper --permanent</span><br><span class="line">$ firewall-cmd --service=zookeeper --add-port 2181/tcp --permanent</span><br><span class="line">$ firewall-cmd --service=zookeeper --add-port 2888/tcp --permanent</span><br><span class="line">$ firewall-cmd --service=zookeeper --add-port 3888/tcp --permanent</span><br><span class="line"><span class="comment"># 不中断服务的重新加载</span></span><br><span class="line">$ firewall-cmd --reload</span><br><span class="line">$ firewall-cmd --add-service=zookeeper</span><br><span class="line"><span class="comment"># 将当前防火墙的规则永久保存；</span></span><br><span class="line">$ firewall-cmd --runtime-to-permanent</span><br></pre></td></tr></table></figure>



<p><strong>6、配置集群其他机器</strong></p>
<p>把配置好的Zookeeper目录复制到其他两台机器上，重复上面4-5步。</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ scp -r /usr/<span class="built_in">local</span>/zookeeper centos-node2:/usr/<span class="built_in">local</span>/</span><br></pre></td></tr></table></figure>

<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ vi /etc/profile </span><br></pre></td></tr></table></figure>

<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">JAVA_HOME=/usr/<span class="built_in">local</span>/java/</span><br><span class="line">JRE_HOME=<span class="variable">$JAVA_HOME</span>/jre</span><br><span class="line">HADOOP_HOME=/usr/<span class="built_in">local</span>/hadoop</span><br><span class="line">CLASSPATH=.:<span class="variable">$JAVA_HOME</span>/lib/dt.jar:<span class="variable">$JAVA_HOME</span>/lib/tools.jar:<span class="variable">$JRE_HOME</span>/lib</span><br><span class="line">ZOOKEEPER_HOME=/usr/<span class="built_in">local</span>/zookeeper</span><br><span class="line"></span><br><span class="line">PATH=<span class="variable">$PATH</span>:<span class="variable">$JAVA_HOME</span>/bin:<span class="variable">$JRE_HOME</span>/bin:<span class="variable">$HADOOP_HOME</span>/bin:<span class="variable">$ZOOKEEPER_HOME</span>/bin</span><br><span class="line"></span><br><span class="line"><span class="built_in">export</span> JAVA_HOME JRE_HOME PATH CLASSPATH HADOOP_HOME HBASE_HOME</span><br></pre></td></tr></table></figure>

<p><strong>7、重启集群</strong></p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ /usr/<span class="built_in">local</span>/zookeeper/bin/zkServer.sh start</span><br></pre></td></tr></table></figure>

<p>3个Zookeeper都要启动。</p>
<p><strong>8、查看集群状态</strong></p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">$ /usr/<span class="built_in">local</span>/zookeeper/bin/zkServer.sh status </span><br><span class="line">ZooKeeper JMX enabled by default</span><br><span class="line">Using config: /usr/<span class="built_in">local</span>/zookeeper/bin/../conf/zoo.cfg</span><br><span class="line">Mode: follower</span><br></pre></td></tr></table></figure>

<h2 id="客户端连接"><a href="#客户端连接" class="headerlink" title="客户端连接"></a>客户端连接</h2><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">./zkCli.sh -server 192.168.99.101:2181</span><br></pre></td></tr></table></figure>

<p>连接本机的不用带-server。</p>
<h2 id="注意"><a href="#注意" class="headerlink" title="注意"></a>注意</h2><p>如果是在单机创建的多个Zookeeper伪集群，需要对应修改配置中的端口、日志文件、数据文件位置等配置信息。</p>

      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="http://littlefxc.github.io/2021/12/20/docs/5G/5G%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="一年春又来">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一年春又来">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/2021/12/20/docs/5G/5G%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/" class="post-title-link" itemprop="url">5G名词</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2021-12-20 02:21:39" itemprop="dateCreated datePublished" datetime="2021-12-20T02:21:39+08:00">2021-12-20</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2022-05-10 09:29:58" itemprop="dateModified" datetime="2022-05-10T09:29:58+08:00">2022-05-10</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E9%80%9A%E4%BF%A1/" itemprop="url" rel="index"><span itemprop="name">通信</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <p>[TOC]</p>
<h2 id="1-名词与缩略语"><a href="#1-名词与缩略语" class="headerlink" title="1 名词与缩略语"></a>1 名词与缩略语</h2><p>LTE: 准4G标准</p>
<p>IMT-2020：5G推进组</p>
<p>SDN：软件定义网络</p>
<p>NFV：网络功能虚拟化</p>
<p>eMBB：增强移动宽带</p>
<p>mMTC：海量机器类通信</p>
<p>URLLC：超可靠低时延通信</p>
<h2 id="2-如何定义5G？"><a href="#2-如何定义5G？" class="headerlink" title="2 如何定义5G？"></a>2 如何定义5G？</h2><p>综合5G关键能力与核心技术，5G概念可由“标志性能力指 标”和“一组关键技术”来共同定义。其中，标志性能力指标为 “Gbps用户体验速率”，一组关键技术包括大规模天线阵列、超密集组网、新型多址、全频谱接入和新型网络架构。</p>
<img src="https://gitee.com/littlefxc/oss/raw/master/images/image-20220107141121089.png" style="zoom:33%;" />

<h2 id="3-5G-架构"><a href="#3-5G-架构" class="headerlink" title="3 5G 架构"></a>3 5G 架构</h2><h3 id="3-1-需求与挑战"><a href="#3-1-需求与挑战" class="headerlink" title="3.1 需求与挑战"></a>3.1 需求与挑战</h3><ol>
<li>关键性能挑战</li>
<li>网络运营需求</li>
</ol>
<h3 id="3-2-设计思路"><a href="#3-2-设计思路" class="headerlink" title="3.2 设计思路"></a>3.2 设计思路</h3><p>从 1G 到 4G，移动网络的演进趋势是控制与转发分离，对于 5G 更是如此，将业务面功能下沉至用户侧。</p>
<p>为了解决网络开放能力和设备兼容性等问题，考虑引入软件和硬件功能解耦技术，以支持网元功能的虚拟化和模块化，便于按需组网。</p>
<p>总结起来，5G 网络需实现转发分离化、部署分布化、网络虚拟化和功能模块化的 4D 逻辑结构。</p>
<p>设计原则：</p>
<ul>
<li>灵活：根据不同的业务需求，构建以用户为中心的组网，支持多种接入技术融合；</li>
<li>高效：简化状态、信令，同时使网络具有更低的传输成本，且易于拓展；</li>
<li>智能：网络能够实现资源的自分配和自调整、组网的自配置和自由化；</li>
<li>开放：网元能够突破软硬件紧耦合的限制，网络能力可向第三方开放，以支持新业务的打造，创新盈利点。</li>
</ul>
<p>特点：一个逻辑架构，多种组网方式</p>
<h3 id="3-3-技术基础"><a href="#3-3-技术基础" class="headerlink" title="3.3 技术基础"></a>3.3 技术基础</h3><p>先决条件：SDN 和 NFV 的结合，有效地满足 5G 网络架构的主要技术特征，使 5G 网络具备网络能力开放性、可编程性、灵活性和可扩展性。</p>
<h4 id="3-3-1-SDN——控制与转发分离"><a href="#3-3-1-SDN——控制与转发分离" class="headerlink" title="3.3.1 SDN——控制与转发分离"></a>3.3.1 SDN——控制与转发分离</h4><p>SDN：软件定义网络</p>
<p>主要特征：控制面与数据面分离和控制面集中化</p>
<p>SDN 的应用场景：</p>
<ol>
<li>场景 1：SDN 在数据中心网络的应用</li>
<li>场景 2：SDN 在数据中心互联的应用</li>
<li>场景 3：SDN 在政企网络中的应用</li>
<li>场景 4：SDN 在电信运营商网络的应用</li>
<li>场景 5：SDN 在互联网公司业务部署中的应用</li>
</ol>
<h4 id="3-3-2-NFV——软件与硬件解耦"><a href="#3-3-2-NFV——软件与硬件解耦" class="headerlink" title="3.3.2 NFV——软件与硬件解耦"></a>3.3.2 NFV——软件与硬件解耦</h4><p>NFV：网络功能虚拟化</p>
<p>NFV 的应用场景：</p>
<ol>
<li>场景 1：虚拟化 BRAS</li>
<li>场景 2：虚拟化 CPE</li>
<li>场景 3：虚拟化 EPC</li>
<li>场景 4：虚拟化 IMS</li>
<li>场景 5：虚拟化路由器 vSR</li>
</ol>
<h4 id="3-3-3-SDN-与-NFV-的关系"><a href="#3-3-3-SDN-与-NFV-的关系" class="headerlink" title="3.3.3 SDN 与 NFV 的关系"></a>3.3.3 SDN 与 NFV 的关系</h4><p>SDN 和 NFV 的共同点是网络从封闭走向开放、从独享的硬件发展到共享的软件。两者具有很强的互补性，但是它们彼此之间是相互独立的，没有必然的依赖性。</p>
<p>SDN 侧重于控制与转发的分离、网络集中控制（逻辑上）和网络虚拟化，主要影响的是网络的结构；</p>
<p>而 NFV 侧重的是软件与硬件的分离、硬件通用化和网络功能虚拟化，主要影响的是网元的形态。</p>
<h3 id="3-4-关键特征"><a href="#3-4-关键特征" class="headerlink" title="3.4 关键特征"></a>3.4 关键特征</h3><ol>
<li>控制转发分离</li>
<li>SBA 架构</li>
<li>网络切片</li>
<li>固移融合</li>
</ol>
<h2 id="4-5G-网络关键技术"><a href="#4-5G-网络关键技术" class="headerlink" title="4 5G 网络关键技术"></a>4 5G 网络关键技术</h2><h3 id="4-1-网络切片"><a href="#4-1-网络切片" class="headerlink" title="4.1 网络切片"></a>4.1 网络切片</h3><h4 id="4-1-1-网络切片架构"><a href="#4-1-1-网络切片架构" class="headerlink" title="4.1.1 网络切片架构"></a>4.1.1 网络切片架构</h4><p>网络切片（NS，Network Slicing）技术通过虚拟化将一个物理网络分成多个虚拟的逻辑网络，每一个虚拟网络对应不同的应用场景，从而提供高能效、易部署的网络解决方案。</p>
<p><img src="https://gitee.com/littlefxc/oss/raw/master/images/%E7%BD%91%E7%BB%9C%E5%88%87%E7%89%87%E5%9C%A85G%E7%BD%91%E7%BB%9C%E4%B8%AD%E7%9A%84%E5%BA%94%E7%94%A8.png"></p>
<p>网络切片架构包含接入侧切片（含无线接入和固定接入）、核心网切片以及将这些切片组成完整切片的选择功能单元。选择功能单元按照实际通信业务需求选择能够提供特定服务的核心网切片。<br><img src="https://gitee.com/littlefxc/oss/raw/master/images/%E7%BD%91%E7%BB%9C%E5%88%87%E7%89%87%E6%9E%B6%E6%9E%84.jpg" alt="网络切片架构"></p>
<p>每个网络切片都是一组网络功能（Network Function）及其资源的集合，由这些网络功能形成一个完整的逻辑网络，每一个逻辑网络都能以特定的网络特征来满足对应业务的需求。通过网络功能和协议定制，网络切片为不同业务场景提供所匹配的网络功能。其中每个切片都可独立按照业务场景的需要和话务模型进行网络功能的定制剪裁和相应网络资源的编排控制，是对 5G 网络架构的实例化。</p>
<h4 id="4-1-2-网络切片实现方案"><a href="#4-1-2-网络切片实现方案" class="headerlink" title="4.1.2 网络切片实现方案"></a>4.1.2 网络切片实现方案</h4><p>NFV 软硬件解耦及动态伸缩特性是 5G 切片的实现基础，而 SDN 的控制与转发分离特性是 5G 切片的实现引擎。</p>
<h3 id="4-2-移动边缘计算——业务本地化"><a href="#4-2-移动边缘计算——业务本地化" class="headerlink" title="4.2 移动边缘计算——业务本地化"></a>4.2 移动边缘计算——业务本地化</h3><p><a target="_blank" rel="noopener" href="https://blog.csdn.net/u013256816/article/details/97858206"> 科普 | 到底什么是移动边缘计算？_朱小厮的博客-CSDN博客</a></p>
<p>低时延业务要求核心网功能部署到网络边缘。</p>
<p><img src="https://gitee.com/littlefxc/oss/raw/master/images/129d356f386eb8cb049fcc47f186fda0.gif"></p>
<h2 id="参考"><a href="#参考" class="headerlink" title="参考"></a>参考</h2><p><a target="_blank" rel="noopener" href="https://www.sdnlab.com/25534.html">硬核图解！30张图带你搞懂！路由器，集线器，交换机，网桥，光猫有啥区别？ (sdnlab.com)</a></p>

      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="http://littlefxc.github.io/2021/12/14/docs/%E5%BE%AE%E6%9C%8D%E5%8A%A1/%E5%88%86%E5%B8%83%E5%BC%8F%E9%99%90%E6%B5%81/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="一年春又来">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一年春又来">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/2021/12/14/docs/%E5%BE%AE%E6%9C%8D%E5%8A%A1/%E5%88%86%E5%B8%83%E5%BC%8F%E9%99%90%E6%B5%81/" class="post-title-link" itemprop="url">分布式限流</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2021-12-14 02:53:59" itemprop="dateCreated datePublished" datetime="2021-12-14T02:53:59+08:00">2021-12-14</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2022-05-10 09:26:38" itemprop="dateModified" datetime="2022-05-10T09:26:38+08:00">2022-05-10</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%88%86%E5%B8%83%E5%BC%8F%E7%B3%BB%E7%BB%9F/" itemprop="url" rel="index"><span itemprop="name">分布式系统</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h2 id="分布式限流介绍"><a href="#分布式限流介绍" class="headerlink" title="分布式限流介绍"></a>分布式限流介绍</h2><p>限流的目的是通过对并发访问/请求进行限速或者在一个时间窗口内的请求进行限速来保护系统，一旦请求到达限制速率则可以拒绝服务、排队或等待、降级。</p>
<p>主要是通过压测时找出每个系统的处理峰值，然后通过处理设定峰值阈值来防止系统过载时，通过拒绝处理过载的请求来保障系统可用性。</p>
<h2 id="分布式限流的几种维度"><a href="#分布式限流的几种维度" class="headerlink" title="分布式限流的几种维度"></a>分布式限流的几种维度</h2><ul>
<li>时间： 限流基于某段时间范围或者某个时间点，也就是我们常说的“时间窗口”，比如对每分钟、每秒钟的时间窗口做限定</li>
<li>资源： 基于可用资源的限制，比如设定最大访问次数，或最高可用连接数</li>
</ul>
<p>上面两个维度结合起来看，限流就是在某个时间窗口对资源访问做限制，比如设定每秒最多100个访问请求。但在真正的场景里，我们不止设置一种限流规则，而是会设置多个限流规则共同作用，主要的几种限流规则如下：</p>
<p><img src="https://gitee.com/littlefxc/oss/raw/master/images/5e0f15a8097b023f27401174.png" alt="img"></p>
<p>一般开发高并发系统常见的限流有：</p>
<ul>
<li>限制总并发数：如数据库连接池、线程池</li>
<li>限制瞬时并发数：如Nginx的 limit_conn 模块</li>
<li>限制时间窗口内的平均速率：如Guava的RateLimiter、Nginx的 limit_req 模块</li>
<li>限制远程接口调用速率</li>
<li>限制MQ的消费速率</li>
<li>等等…</li>
<li>还可以根据网络连接数、网络流量、CPU或内存负载</li>
</ul>
<h2 id="限流算法"><a href="#限流算法" class="headerlink" title="限流算法"></a>限流算法</h2><h3 id="令牌桶算法"><a href="#令牌桶算法" class="headerlink" title="令牌桶算法"></a>令牌桶算法</h3><p><img src="https://gitee.com/littlefxc/oss/raw/master/images/image-20211207163639135.png" alt="image-20211207163639135"></p>
<p><img src="https://gitee.com/littlefxc/oss/raw/master/images/image-20211207163552357.png" alt="image-20211207163552357"></p>
<p><img src="https://gitee.com/littlefxc/oss/raw/master/images/5e0f176d09e1a32330281388.png" alt="img"></p>
<p>有两个关键的角色：</p>
<ul>
<li>令牌：获取到令牌的Request才会被处理，其他Requests要么排队要么被直接丢弃</li>
<li>桶：用来装令牌的地方，所有Request都从这个桶里面获取令牌</li>
</ul>
<p>两个关键流程：</p>
<ul>
<li><p>生成令牌</p>
<p>这个流程涉及到令牌生成器和令牌桶，令牌桶是一个装令牌的地方，既然是个桶那么必然有一个容量，也就是说令牌桶所能容纳的令牌数量是一个固定的数值。</p>
<p>对于令牌生成器来说，它会根据一个预定的速率向桶中添加令牌，比如我们可以配置让它以每秒100个请求的速率发放令牌，或者每分钟50个。注意这里的发放速度是匀速，也就是说这50个令牌并非是在每个时间窗口刚开始的时候一次性发放，而是会在这个时间窗口内匀速发放。</p>
<p>在令牌发放器就是一个水龙头，假如在下面接水的桶子满了，那么自然这个水（令牌）就流到了外面。在令牌发放过程中也一样，令牌桶的容量是有限的，如果当前已经放满了额定容量的令牌，那么新来的令牌就会被丢弃掉。</p>
</li>
<li><p>获取令牌</p>
<p>每个访问请求到来后，必须获取到一个令牌才能执行后面的逻辑。假如令牌的数量少，而访问请求较多的情况下，一部分请求自然无法获取到令牌，那么这个时候我们可以设置一个“缓冲队列”来暂存这些多余的令牌。</p>
<p><strong>缓冲队列</strong>其实是一个可选的选项，并不是所有应用了令牌桶算法的程序都会实现队列。当有缓存队列存在的情况下，那些暂时没有获取到令牌的请求将被放到这个队列中排队，直到新的令牌产生后，再从队列头部拿出一个请求来匹配令牌。</p>
<p>当队列已满的情况下，这部分访问请求将被丢弃。在实际应用中我们还可以给这个队列加一系列的特效，比如设置队列中请求的存活时间，或者将队列改造为PriorityQueue，根据某种优先级排序，而不是先进先出。算法是死的，人是活的，先进的生产力来自于不断的创造，在技术领域尤其如此。</p>
</li>
</ul>
<h3 id="漏桶算法"><a href="#漏桶算法" class="headerlink" title="漏桶算法"></a>漏桶算法</h3><p><img src="https://gitee.com/littlefxc/oss/raw/master/images/5e0f177b09c240dc25841544.png" alt="img"></p>
<p>漏桶算法的前半段和令牌桶类似，但是操作的对象不同，令牌桶是将令牌放入桶里，而漏桶是将访问请求的数据包放到桶里。同样的是，如果桶满了，那么后面新来的数据包将被丢弃。</p>
<p>漏桶算法的后半程是有鲜明特色的，它永远只会以一个恒定的速率将数据包从桶内流出。打个比方，如果我设置了漏桶可以存放100个数据包，然后流出速度是1s一个，那么不管数据包以什么速率流入桶里，也不管桶里有多少数据包，漏桶能保证这些数据包永远以1s一个的恒定速度被处理。</p>
<h3 id="令漏洞算法-VS-漏洞算法"><a href="#令漏洞算法-VS-漏洞算法" class="headerlink" title="令漏洞算法 VS 漏洞算法"></a>令漏洞算法 VS 漏洞算法</h3><p><strong>漏桶</strong></p>
<p>漏桶的出水速度是恒定的，那么意味着如果瞬时大流量的话，将有大部分请求被丢弃掉（也就是所谓的溢出）。</p>
<p><strong>令牌桶</strong></p>
<p>生成令牌的速度是恒定的，而请求去拿令牌是没有速度限制的。这意味，面对瞬时大流量，<em>该算法可以在短时间内请求拿到大量令牌</em>，而且拿令牌的过程并不是消耗很大的事情。</p>
<p>最后，不论是对于令牌桶拿不到令牌被拒绝，还是漏桶的水满了溢出，都是为了保证大部分流量的正常使用，而牺牲掉了少部分流量，这是合理的，如果因为极少部分流量需要保证的话，那么就可能导致系统达到极限而挂掉，得不偿失。</p>
<h3 id="滑动窗口"><a href="#滑动窗口" class="headerlink" title="滑动窗口"></a>滑动窗口</h3><p><img src="https://gitee.com/littlefxc/oss/raw/master/images/5e0f17870983b50a33121060.png" alt="img"></p>
<p>上图中黑色的大框就是时间窗口，我们设定窗口时间为5秒，它会随着时间推移向后滑动。我们将窗口内的时间划分为五个小格子，每个格子代表1秒钟，同时这个格子还包含一个计数器，用来计算在当前时间内访问的请求数量。那么这个时间窗口内的总访问量就是所有格子计数器累加后的数值。</p>
<p>比如说，我们在每一秒内有5个用户访问，第5秒内有10个用户访问，那么在0到5秒这个时间窗口内访问量就是15。如果我们的接口设置了时间窗口内访问上限是20，那么当时间到第六秒的时候，这个时间窗口内的计数总和就变成了10，因为1秒的格子已经退出了时间窗口，因此在第六秒内可以接收的访问量就是20-10=10个。</p>
<p>滑动窗口其实也是一种计算器算法，它有一个显著特点，当时间窗口的跨度越长时，限流效果就越平滑。打个比方，如果当前时间窗口只有两秒，而访问请求全部集中在第一秒的时候，当时间向后滑动一秒后，当前窗口的计数量将发生较大的变化，拉长时间窗口可以降低这种情况的发生概率</p>
<h2 id="限流组件"><a href="#限流组件" class="headerlink" title="限流组件"></a>限流组件</h2><h3 id="Guava-RateLimiter-客户端限流"><a href="#Guava-RateLimiter-客户端限流" class="headerlink" title="Guava RateLimiter 客户端限流"></a>Guava RateLimiter 客户端限流</h3><h4 id="引入依赖项"><a href="#引入依赖项" class="headerlink" title="引入依赖项"></a>引入依赖项</h4><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>com.google.guava<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>guava<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h4 id="非阻塞式的限流方案"><a href="#非阻塞式的限流方案" class="headerlink" title="非阻塞式的限流方案"></a>非阻塞式的限流方案</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Slf4j</span></span><br><span class="line"><span class="meta">@RestController</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">RateLimiterController</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">private</span> RateLimiter rateLimiter = RateLimiter.create(<span class="number">2.0</span>);</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 非阻塞限流</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> count   请求令牌数</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> timeout 请求令牌超时时间, 如果等于0, 表示不限定时间</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="meta">@GetMapping(&quot;/tryAcquire&quot;)</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">tryAcquire</span><span class="params">(Integer count, <span class="meta">@RequestParam(defaultValue = &quot;0&quot;)</span> Integer timeout)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">if</span> (rateLimiter.tryAcquire(count, timeout, TimeUnit.SECONDS)) &#123;</span><br><span class="line">            log.info(<span class="string">&quot;success, rate is &#123;&#125;&quot;</span>, rateLimiter.getRate());</span><br><span class="line">            <span class="keyword">return</span> <span class="string">&quot;success&quot;</span>;</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            log.info(<span class="string">&quot;fail, rate is &#123;&#125;&quot;</span>, rateLimiter.getRate());</span><br><span class="line">            <span class="keyword">return</span> <span class="string">&quot;fail&quot;</span>;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="同步阻塞式的限流方案"><a href="#同步阻塞式的限流方案" class="headerlink" title="同步阻塞式的限流方案"></a>同步阻塞式的限流方案</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Slf4j</span></span><br><span class="line"><span class="meta">@RestController</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">RateLimiterController</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">private</span> RateLimiter rateLimiter = RateLimiter.create(<span class="number">2.0</span>);</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 同步阻塞式限流</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> count 请求令牌数</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="meta">@GetMapping(&quot;/acquire&quot;)</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">acquire</span><span class="params">(<span class="meta">@RequestParam(defaultValue = &quot;1&quot;)</span> Integer count)</span> </span>&#123;</span><br><span class="line">        rateLimiter.acquire(count);</span><br><span class="line">        log.info(<span class="string">&quot;success, rate is &#123;&#125;&quot;</span>, rateLimiter.getRate());</span><br><span class="line">        <span class="keyword">return</span> <span class="string">&quot;success&quot;</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="基于Nginx-的IP限流、服务器级别限流"><a href="#基于Nginx-的IP限流、服务器级别限流" class="headerlink" title="基于Nginx 的IP限流、服务器级别限流"></a>基于Nginx 的IP限流、服务器级别限流</h3><p>nginx 的配置</p>
<figure class="highlight nginx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 根据 IP 限制速度 </span></span><br><span class="line"><span class="comment"># 1) $binary_remote_addr : binary_ 目的是缩写内存占用，remote_addr 表示通过 IP 地址来限流</span></span><br><span class="line"><span class="comment"># 2) zone=iplimit:20m : iplimit 是一个内存区域（记录访问频率信息），20m 是指这块内存区域大小</span></span><br><span class="line"><span class="comment"># 3) rate=1r/s : r 代表 request，s 代表 seconds，比如 100r/m，标识访问的限流频率</span></span><br><span class="line"><span class="attribute">limit_req_zone</span> $binary_remote_addr zone=iplimit:<span class="number">20m</span> rate=10r/s;</span><br><span class="line"></span><br><span class="line"><span class="comment"># 根据服务器级别做限流，一般的，服务器级别的限流速率是很大的，但为了测试，才改的比上面的小</span></span><br><span class="line"><span class="attribute">limit_req_zone</span> $server_name zone=serverlimit:<span class="number">10m</span> rate=1r/s;</span><br><span class="line"></span><br><span class="line"><span class="section">server</span> &#123;</span><br><span class="line">    <span class="attribute">listen</span> <span class="number">80</span></span><br><span class="line">    server_name www.rate-limiter.com</span><br><span class="line">    location /access-limit/ &#123;</span><br><span class="line">        <span class="attribute">proxy_pass</span> http://127.0.0.1:10000/;</span><br><span class="line">        <span class="comment"># 1) zone=iplimit : 引用 limit_req_zone 中的 zone 变量</span></span><br><span class="line">        <span class="comment"># 2) burst=2 : 设置一个大小为 2 的缓冲区域，当大量请求到来，请求数量超过限流频率时，将其放入缓冲区域</span></span><br><span class="line">        <span class="comment"># 3) nodelay : 缓冲区满了以后，直接返回 503 异常</span></span><br><span class="line">        <span class="attribute">limit_req</span> zone=iplimit burst=<span class="number">2</span> nodelay;</span><br><span class="line">    </span><br><span class="line">        <span class="attribute">limit_req</span> zone=serverlimit burst=<span class="number">1</span> nodelay;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="基于Nginx-的连接数限制和单机限制"><a href="#基于Nginx-的连接数限制和单机限制" class="headerlink" title="基于Nginx 的连接数限制和单机限制"></a>基于Nginx 的连接数限制和单机限制</h3><p>nginx 的配置</p>
<figure class="highlight nginx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 基于连接数、IP的限流配置</span></span><br><span class="line"><span class="attribute">limit_conn_zone</span> $binary_remote_addr zone=perip:<span class="number">20m</span>;</span><br><span class="line"><span class="comment"># 基于连接数、服务器的限流配置</span></span><br><span class="line"><span class="attribute">limit_conn_zone</span> $server_name zone=perserver:<span class="number">20m</span>;</span><br><span class="line"></span><br><span class="line"><span class="section">server</span> &#123;</span><br><span class="line">    <span class="attribute">listen</span>      <span class="number">80</span>;</span><br><span class="line">    <span class="attribute">server_name</span> www.rate-limiter.com;</span><br><span class="line">    <span class="attribute">location</span> /access-limit/ &#123;</span><br><span class="line">        <span class="attribute">proxy_pass</span> http://127.0.0.1:10000/;</span><br><span class="line">    </span><br><span class="line">        <span class="comment"># 每个 IP 地址最多保持 1 个连接</span></span><br><span class="line">        <span class="attribute">limit_conn</span> perip <span class="number">1</span>;</span><br><span class="line">        <span class="comment"># 每个 server 做多保持 100 个连接</span></span><br><span class="line">        <span class="attribute">limit_conn</span> perserver <span class="number">100</span>;</span><br><span class="line"></span><br><span class="line">        <span class="comment"># 异常情况返回的 HTTP 状态码, 默认 503；</span></span><br><span class="line">        <span class="attribute">limit_req_status</span> <span class="number">504</span>;</span><br><span class="line">        <span class="attribute">limit_conn_status</span> <span class="number">504</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="TODO-基于Nginx-Lua-Redis-实现动态封禁-IP"><a href="#TODO-基于Nginx-Lua-Redis-实现动态封禁-IP" class="headerlink" title="TODO 基于Nginx + Lua + Redis 实现动态封禁 IP"></a>TODO 基于Nginx + Lua + Redis 实现动态封禁 IP</h3><ul>
<li><input disabled="" type="checkbox"> <a target="_blank" rel="noopener" href="https://mp.weixin.qq.com/s/7qZfMwSyIXYawZegoI1OLw">Nginx 通过 Lua + Redis 实现动态封禁 IP</a></li>
</ul>
<h3 id="基于Redis-Lua的分布式限流"><a href="#基于Redis-Lua的分布式限流" class="headerlink" title="基于Redis+Lua的分布式限流"></a>基于Redis+Lua的分布式限流</h3><p>Lua 限流脚本</p>
<figure class="highlight lua"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">-- 用作限流的 Key, （一秒一个）</span></span><br><span class="line"><span class="keyword">local</span> key = KEYS[<span class="number">1</span>]</span><br><span class="line">redis.<span class="built_in">log</span>(redis.LOG_DEBUG, <span class="string">&#x27;key is &#x27;</span>, key)</span><br><span class="line"></span><br><span class="line"><span class="comment">-- 限流的最大阈值</span></span><br><span class="line"><span class="keyword">local</span> limit = <span class="built_in">tonumber</span>(ARGV[<span class="number">1</span>])</span><br><span class="line"></span><br><span class="line"><span class="comment">-- 当前流量大小</span></span><br><span class="line"><span class="keyword">local</span> current = <span class="built_in">tonumber</span>(redis.call(<span class="string">&quot;get&quot;</span>, key) <span class="keyword">or</span> <span class="string">&quot;0&quot;</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment">-- 如果超出限流大小</span></span><br><span class="line"><span class="keyword">if</span> current + <span class="number">1</span> &gt; limit <span class="keyword">then</span></span><br><span class="line">    <span class="keyword">return</span> <span class="literal">false</span></span><br><span class="line"><span class="keyword">else</span></span><br><span class="line">    <span class="comment">-- 请求数 +1，并设置 2 秒过期</span></span><br><span class="line">    redis.call(<span class="string">&quot;INCRBY&quot;</span>, key, <span class="string">&quot;1&quot;</span>)</span><br><span class="line">    redis.call(<span class="string">&quot;expire&quot;</span>, key, <span class="string">&quot;2&quot;</span>)</span><br><span class="line">    <span class="keyword">return</span> <span class="literal">true</span></span><br><span class="line"><span class="keyword">end</span></span><br></pre></td></tr></table></figure>

<p>使用 spring-boot-starter-data-redis 结合 lua 限流脚本</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Slf4j</span></span><br><span class="line"><span class="meta">@Aspect</span></span><br><span class="line"><span class="meta">@Component</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">AccessLimiterAspect</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Autowired</span></span><br><span class="line">    <span class="keyword">private</span> RedisLuaAccessLimiter redisLuaAccessLimiter;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Pointcut(&quot;@annotation(AccessLimiter)&quot;)</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">cut</span><span class="params">()</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Before(value = &quot;cut()&quot;)</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">before</span><span class="params">(JoinPoint joinPoint)</span> </span>&#123;</span><br><span class="line">        <span class="comment">// 获取方法签名作为 KEY</span></span><br><span class="line">        MethodSignature signature = (MethodSignature) joinPoint.getSignature();</span><br><span class="line">        Method method = signature.getMethod();</span><br><span class="line"></span><br><span class="line">        AccessLimiter annotation = method.getAnnotation(AccessLimiter.class);</span><br><span class="line">        String key = annotation.key();</span><br><span class="line">        <span class="keyword">if</span> (StringUtils.isBlank(key)) &#123;</span><br><span class="line">            <span class="comment">// 如果没有设置 key，就自动生成</span></span><br><span class="line">            Class&lt;?&gt;[] parameterTypes = method.getParameterTypes();</span><br><span class="line">            key = method.getName();</span><br><span class="line">            String paramTypes = Arrays.stream(parameterTypes)</span><br><span class="line">                    .map(Class::getName)</span><br><span class="line">                    .collect(Collectors.joining(<span class="string">&quot;,&quot;</span>));</span><br><span class="line">            key += (<span class="string">&quot;#&quot;</span> + paramTypes);</span><br><span class="line">        &#125;</span><br><span class="line">        Integer limit = annotation.limit();</span><br><span class="line"></span><br><span class="line">        <span class="comment">// 调用redis</span></span><br><span class="line">        redisLuaAccessLimiter.limitAccess(key, limit);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>


      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="http://littlefxc.github.io/2021/12/07/%E5%88%86%E5%B8%83%E5%BC%8F%E9%99%90%E6%B5%81/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="一年春又来">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一年春又来">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/2021/12/07/%E5%88%86%E5%B8%83%E5%BC%8F%E9%99%90%E6%B5%81/" class="post-title-link" itemprop="url">分布式限流</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2021-12-07 15:46:47" itemprop="dateCreated datePublished" datetime="2021-12-07T15:46:47+08:00">2021-12-07</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2022-05-10 09:54:13" itemprop="dateModified" datetime="2022-05-10T09:54:13+08:00">2022-05-10</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%88%86%E5%B8%83%E5%BC%8F%E7%B3%BB%E7%BB%9F/" itemprop="url" rel="index"><span itemprop="name">分布式系统</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <p>[TOC]</p>
<h1 id="分布式限流介绍"><a href="#分布式限流介绍" class="headerlink" title="分布式限流介绍"></a>分布式限流介绍</h1><p>限流的目的是通过对并发访问/请求进行限速或者在一个时间窗口内的请求进行限速来保护系统，一旦请求到达限制速率则可以拒绝服务、排队或等待、降级。</p>
<p>主要是通过压测时找出每个系统的处理峰值，然后通过处理设定峰值阈值来防止系统过载时，通过拒绝处理过载的请求来保障系统可用性。</p>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/2021/12/07/%E5%88%86%E5%B8%83%E5%BC%8F%E9%99%90%E6%B5%81/#more" rel="contents">
                阅读全文 &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="http://littlefxc.github.io/2021/12/06/%E6%8E%A5%E5%8F%A3%E5%B9%82%E7%AD%89%E6%80%A7/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="一年春又来">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一年春又来">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/2021/12/06/%E6%8E%A5%E5%8F%A3%E5%B9%82%E7%AD%89%E6%80%A7/" class="post-title-link" itemprop="url">接口幂等性</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2021-12-06 14:22:46" itemprop="dateCreated datePublished" datetime="2021-12-06T14:22:46+08:00">2021-12-06</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2021-12-07 15:47:15" itemprop="dateModified" datetime="2021-12-07T15:47:15+08:00">2021-12-07</time>
      </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h1 id="什么是幂等性？"><a href="#什么是幂等性？" class="headerlink" title="什么是幂等性？"></a>什么是幂等性？</h1><ul>
<li>幂等性：f(f(x)) = f(x)</li>
<li>幂等元素运行多次，还等于它原来的运算结果</li>
<li>在系统中，一个接口运行多次，与运行一次的效果是一致的</li>
</ul>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/2021/12/06/%E6%8E%A5%E5%8F%A3%E5%B9%82%E7%AD%89%E6%80%A7/#more" rel="contents">
                阅读全文 &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="http://littlefxc.github.io/2021/10/21/%E8%B4%9F%E8%BD%BD%E5%9D%87%E8%A1%A1Ribbon/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="一年春又来">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一年春又来">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/2021/10/21/%E8%B4%9F%E8%BD%BD%E5%9D%87%E8%A1%A1Ribbon/" class="post-title-link" itemprop="url">负载均衡Ribbon</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2021-10-21 12:01:22" itemprop="dateCreated datePublished" datetime="2021-10-21T12:01:22+08:00">2021-10-21</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2022-05-10 09:54:27" itemprop="dateModified" datetime="2022-05-10T09:54:27+08:00">2022-05-10</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%88%86%E5%B8%83%E5%BC%8F%E7%B3%BB%E7%BB%9F/" itemprop="url" rel="index"><span itemprop="name">分布式系统</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h1 id="负载均衡介绍"><a href="#负载均衡介绍" class="headerlink" title="负载均衡介绍"></a>负载均衡介绍</h1><p>将请求或者说流量，以期望的规则分摊到多个操作单元上进行执行。</p>
<p>通过它可以实现横向扩展(scale out)，将冗余的作用发挥为高可用。另外，还可以物尽其用，提升资源使用率。</p>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/2021/10/21/%E8%B4%9F%E8%BD%BD%E5%9D%87%E8%A1%A1Ribbon/#more" rel="contents">
                阅读全文 &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




  <nav class="pagination">
    <a class="extend prev" rel="prev" href="/page/2/"><i class="fa fa-angle-left" aria-label="上一页"></i></a><a class="page-number" href="/">1</a><a class="page-number" href="/page/2/">2</a><span class="page-number current">3</span><a class="page-number" href="/page/4/">4</a><span class="space">&hellip;</span><a class="page-number" href="/page/24/">24</a><a class="extend next" rel="next" href="/page/4/"><i class="fa fa-angle-right" aria-label="下一页"></i></a>
  </nav>


<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      const activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      const commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>
</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">


<div class="copyright">
  &copy; 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">一年春又来</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/mist/" class="theme-link" rel="noopener" target="_blank">NexT.Mist</a> 强力驱动
  </div>

    </div>
  </footer>

  
  <script src="https://cdn.jsdelivr.net/npm/animejs@3.2.1/lib/anime.min.js"></script>
<script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/schemes/muse.js"></script><script src="/js/next-boot.js"></script>

  
<script src="/js/local-search.js"></script>






  





</body>
</html>
